package com.example.springboottemplate.Config.Interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Component
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    private MyInterceptor myInterceptor;

    /*
     *  MVC拦截器处理拦截粒度
     * */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册拦截器并指定拦截路径
        registry.addInterceptor(myInterceptor).addPathPatterns("/**");
    }

    /*
     *  加载静态资源(若有需求进行操作)
     * */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /*
         *  knief4j避免mvc将其视作控制层请求路径 将其视为一个静态资源
         * */
        registry.addResourceHandler("/doc.html")
                .addResourceLocations("classpath:/META-INF/resources/");
    }
}